Technique: Programming with Effects
Code often has a happy-path to the goal, but needs to consider a lot of error cases as well. These error cases deviate from the path and need to be handled, in software we can leverage several solutions differing in their power to similar problems:
- Error codes. A simple solution is to return an error code in case of an error and handle that.
- Exceptions. Exceptions enable a clean separation between the code that raises an exception and the code that handles it.
- Coroutines. Besides raising an exception and therefore stopping code, alternatively, a coroutine can suspend execution with a question and other code can resume the coroutine with an answer.
- Continuations. Further, it might be possible to create a copy of the current program execution state, resume execution and then later backtrack and continue execution with a different value.
At some point we no longer consider the exceptions as "side"-effects, e.g., things which went wrong, but instead we use the continuations as equally important parts of the primary goal of some functionality -- an effect. Effect handlers as generalizations of exception handlers offer interesting new ways to modularize software. Effects and co-effects can accurately represent additional capabilities and restrictions on parts of code.
In a project, we could learn how to use such an effect system and implement some case studies, or implement part of an effect compiler yourself following some papers. For the seminar, a few recent papers on this topic would be the following -- depending on your interest, we might find older or more recent other papers as well: